﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CNotebook
{
    public abstract class ConnectionManager
    {
        public string ConnectionString { get; set; }

        SqlConnection _CONNECTION = new SqlConnection();
        public SqlConnection Connection
        {
            get { return _CONNECTION; }
            set { _CONNECTION = value; }
        }
        public SqlException Open()
        {
            try
            {
                _CONNECTION.ConnectionString = this.ConnectionString;
                _CONNECTION.Open();
                return null;

            }
            catch (SqlException ex)
            {
                _CONNECTION.Dispose();
                return ex;
            }
        }

        public SqlException Close()
        {
            try
            {
                _CONNECTION.Close();

                return null;
            }
            catch (SqlException ex)
            {
                return ex;
            }
            finally
            {
                _CONNECTION.Dispose();  
            }
        }
    }
}
